package com.bridgeintelligent.tag.user.query.web;


import com.bridgeintelligent.tag.user.mgmt.entity.Result;
import com.bridgeintelligent.tag.user.mgmt.entity.UserCodes;
import com.bridgeintelligent.tag.user.mgmt.pojo.Power;
import com.bridgeintelligent.tag.user.mgmt.pojo.Role;
import com.bridgeintelligent.tag.user.query.service.RoleQueryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 角色查询控制层
 */
@Api(tags = "角色查询")
@RestController
@RequestMapping("/api/role")
public class RoleQueryController {

    @Autowired
    private RoleQueryService roleQueryService;

    /**
     * 根据角色id查询单个角色信息及其权限信息
     *
     * @param roleId
     * @return
     */
    @ApiOperation("根据角色id查询单个角色信息及其权限信息")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "path", name = "roleId", value = "角色id")})
    @GetMapping("/findOneByRoleId/{roleId}")
    public Result findOneByRoleId(@PathVariable String roleId) {

        Map<String, Object> map = roleQueryService.findOneByRoleId(roleId);

        return new Result(UserCodes.SUCCESS, map);
    }

    /**
     * 查询所有角色信息
     *
     * @return
     */
    @ApiOperation("查询所有角色信息")
    @GetMapping("/findAllRole")
    public Result findAllRole() {

        List<Role> roleList = roleQueryService.findAllRole();

        return new Result(UserCodes.SUCCESS, roleList);
    }

    /**
     * 获取角色列表
     *
     * @return
     */
    @ApiOperation("获取角色列表")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "pageNumber", value = "页码"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "条数"),
            @ApiImplicitParam(paramType = "query", name = "roleName", value = "角色名称"),
    })
    @GetMapping("/list")
    public Result list(Integer pageNumber, Integer pageSize, String roleName) {
        pageNumber = pageNumber == null ? 1 : pageNumber;
        pageSize = pageSize == null ? 10 : pageSize;
        return roleQueryService.list(pageNumber, pageSize, roleName);
    }

    @ApiOperation("查询所有权限列表")
    @GetMapping("/findAllPower")
    public Result findAllPower() {
        List<Power> powerList = roleQueryService.findAllPower(UserCodes.POWERPARENTID);
        return new Result(UserCodes.SUCCESS, powerList);
    }


}